#ifndef WXSRESOURCETREE_H
#define WXSRESOURCETREE_H

#include <wx/treectrl.h>
#include "wxsresourcetreeitemdata.h"

#if defined(__WXMSW__) && defined(LoadImage)
#undef LoadImage
#endif


class wxsResource;
class wxsProject;


typedef wxTreeItemId wxsResourceItemId;



class wxsResourceTree: public wxTreeCtrl {
  public:


    wxsResourceTree( wxWindow* Parent );


    virtual ~wxsResourceTree();


    wxsResourceItemId NewProjectItem( const wxString& ProjectTitle, wxsProject* Project );


    wxsResourceItemId ExternalResourcesId();


    void DeleteExternalResourcesId();


    static inline wxsResourceTree* Get() { return m_Singleton; }


    static wxImageList& GetGlobalImageList();


    static int LoadImage( const wxString& FileName );


    static int InsertImage( const wxBitmap& Bitmap );


    static void FreeImage( int Index );


    void BlockSelect();


    void UnblockSelect();

  private:

    wxsResourceItemId m_ExtId;              ///< \brief id of tree item containing external resources
    bool m_IsExt;                           ///< \brief True if there is item for external resources
    int m_BlockCount;                       ///< \brief if > 0 must block all select events
    wxsResourceTreeItemData* m_Data;        ///< \brief Pointer to item data object used in last action
    static wxsResourceTree* m_Singleton;
    static int m_RootImageId;
    static int m_ProjectImageId;
    static int m_ExternalImageId;

    static wxArrayInt& GetFreedList();

    void PopupMenu( wxMenu* Menu, wxsResourceTreeItemData* ItemData );
    void InvalidateItemData( wxsResourceTreeItemData* ItemData );

    void OnSelect( wxTreeEvent& event );
    void OnRightClick( wxTreeEvent& event );
    void OnPopupMenu( wxCommandEvent& event );

    friend void wxsResourceTreeItemData::PopupMenu( wxMenu* Menu );
    friend wxsResourceTreeItemData::~wxsResourceTreeItemData();

    DECLARE_EVENT_TABLE()
};


inline wxsResourceTree* wxsTree() { return wxsResourceTree::Get(); }

#endif
